package com.ttg.web.controller.common;

import com.ttg.common.entities.BaseResult;
import com.ttg.common.utils.RequestParamsManager;
import com.ttg.model.PeopleDto;
import com.ttg.model.dto.*;
import com.ttg.web.service.PeopleInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 人群与画像管理
 */
@RestController
@RequestMapping("/people")
public class PeopleInfoController {

    @Autowired
    private PeopleInfoService peopleInfoService;

    /**
     * 预估人数
     */
    @PostMapping("/ProjectNum")
    public BaseResult ProjectNum(@RequestBody String data){
        PeopleInfoDto peopleInfoDto = RequestParamsManager.transformRequestParam(data, PeopleInfoDto.class);
        return peopleInfoService.ProjectNum(peopleInfoDto);
    }



    /**
     *添加人群
     */
    @PostMapping("/add")
    public BaseResult add(@RequestBody String data){
        PeopleInfoDto dto = RequestParamsManager.transformRequestParam(data, PeopleInfoDto.class);
        return peopleInfoService.add(dto);
    }


    /**
     *人群列表
     */
    @PostMapping("/getList")
    public BaseResult getList(@RequestBody String data){
        PeopleInfoGetListDto dto = RequestParamsManager.transformRequestParam(data, PeopleInfoGetListDto.class);
        return peopleInfoService.getList(dto);
    }

    /**
     * 删除人群(逻辑删除)
     */
    @PostMapping("/delete")
    public BaseResult delete(@RequestBody String data){
        PeopleDto dto = RequestParamsManager.transformRequestParam(data, PeopleDto.class);
        return peopleInfoService.delete(dto);
    }

    /**
     * 获取单个人群信息
     */
    @PostMapping("getOne")
    public BaseResult getOne(@RequestBody String data){
        PeopleDto dto = RequestParamsManager.transformRequestParam(data, PeopleDto.class);
        return peopleInfoService.getOne(dto);
    }

    /**
     * 修改人群
     */
    @PostMapping("/update")
    public BaseResult update(@RequestBody String data){
        PeopleInfoDto dto = RequestParamsManager.transformRequestParam(data, PeopleInfoDto.class);
        return peopleInfoService.update(dto);
    }

    /**
     * 单个人群更新
     * @param data
     * @return
     */
    @RequestMapping("/update/peopleBind")
    public BaseResult peopleBind(@RequestBody(required = false) String data){
        PeopleBindDto reqDto = RequestParamsManager.transformRequestParam(data, PeopleBindDto.class);
        return peopleInfoService.peopleBind(reqDto);
    }

    /**
     * 查看历史执行详情
     * @param data
     * @return
     */
    @RequestMapping("/getHistoryList")
    public BaseResult getHistoryList(@RequestBody String data){
        PeopleHistoryDto reqDto = RequestParamsManager.transformRequestParam(data, PeopleHistoryDto.class);
        return peopleInfoService.getHistoryList(reqDto);
    }

    /**
     * 人群导出
     * @param data
     * @param response
     */
    @RequestMapping("/export")
    public void export(@RequestBody(required = false) String data, HttpServletResponse response){
        PeopleInfoGetListDto reqDto = RequestParamsManager.transformRequestParam(data, PeopleInfoGetListDto.class);
        peopleInfoService.export(reqDto, response);
    }
}
